package com.liucxu.zimuzu.View.Fragement;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.liucxu.zimuzu.Base.BaseFragment;
import com.liucxu.zimuzu.R;
import com.liucxu.zimuzu.Utils.ViewUtils;
import com.liucxu.zimuzu.View.Adapter.HotMovieTvFragmentAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 热门Fragment，其中包含电影和TV两种
 * 下部使用Viewpager，上面使用TabLayout
 */
public class HotMovieTvFragment extends BaseFragment {

    private TabLayout tab_layout;
    private ViewPager view_pager;
    private List<BaseFragment> fragments = new ArrayList<>();
    private List<String> titles = new ArrayList<>();
    private HotMovieTvFragmentAdapter mHotMovieTvFragmentAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_hot_movie_tv;
    }

    @Override
    public void setupView() {
        tab_layout = (TabLayout) $(R.id.tab_layout);
        view_pager = (ViewPager) $(R.id.view_pager);
    }

    @Override
    public void setupData() {
        fragments.clear();
        titles.clear();
        BaseFragment movieFragment = ViewUtils.createFragment(HotFragment.class, false);
        Bundle bundle_movie = new Bundle();
        bundle_movie.putString("channel", "movie");
        movieFragment.setArguments(bundle_movie);
        BaseFragment tvFragment = ViewUtils.createFragment(HotFragment.class, false);
        Bundle bundle_tv = new Bundle();
        bundle_tv.putString("channel", "tv");
        tvFragment.setArguments(bundle_tv);
        fragments.add(movieFragment);
        fragments.add(tvFragment);
        titles.add("Movie");
        titles.add("Tv");
        mHotMovieTvFragmentAdapter = new HotMovieTvFragmentAdapter(getChildFragmentManager(), titles, fragments);
        view_pager.setAdapter(mHotMovieTvFragmentAdapter);
        tab_layout.setupWithViewPager(view_pager);
        tab_layout.setTabsFromPagerAdapter(mHotMovieTvFragmentAdapter);
    }

}
